package com.eeb.dropwizardmongo.example.api;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.hibernate.validator.constraints.NotBlank;
import org.mongojack.MongoCollection;
import org.mongojack.ObjectId;

import java.util.ArrayList;
import java.util.List;

@JsonIgnoreProperties(ignoreUnknown = true)
@MongoCollection(name = "organizations")
public class Organization {

    @JsonProperty("_id")
    private String _id;

    @NotBlank
    @JsonProperty("name")
    private String name;

    @JsonProperty("admins")
    private List<String> admins = new ArrayList<>();
    
    @JsonProperty("tracks")
    private List<String> tracks = new ArrayList<>();

    @JsonProperty("users")
    private List<String> users = new ArrayList<>();

    public Organization() {
    }

    public Organization(@ObjectId String _id, String name, List<String> admins) {
        this._id = _id;
        this.name = name;
        this.admins = admins;
    }

    @ObjectId
    public String get_id() {
        return _id;
    }

    public void set_id(String _id) {
        this._id = _id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<String> getAdmins() {
        return admins;
    }

    public void setAdmins(List<String> admins) {
        this.admins = admins;
    }

    public void addAdmin(String admin) {
        if (!admins.contains(admin)) admins.add(admin);
    }

    public boolean removeAdmin(String admin) {
        return admins.remove(admin);
    }

    public boolean hasAdmin(String admin) {
        return admins.contains(admin);
    }

    public List<String> getTracks() {
        return tracks;
    }

    public void setTracks(List<String> tracks) {
        this.tracks = tracks;
    }

    public void addTrack(String track) {
        if (!tracks.contains(track)) tracks.add(track);
    }

    public boolean removeTrack(String track) {
        return tracks.remove(track);
    }

    public boolean hasTrack(String track) {
        return tracks.contains(track);
    }

    public List<String> getUsers() {
        return users;
    }

    public void setUsers(List<String> users) {
        this.users = users;
    }

    public void addUser(String user) {
        if (!users.contains(user)) users.add(user);
    }

    public boolean removeUser(String user) {
        return users.remove(user);
    }

    public boolean hasUser(String user) {
        return users.contains(user);
    }

}